﻿using Chain.BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public partial class Mobile_New_shop : System.Web.UI.Page
{
    private decimal TotalSubtotal;

    private void DataBindGoodCard(HttpCookie cookie)
    {
        Goods MicroWebsiteGoodsBll = new Goods();
        StringBuilder sbWhere = new StringBuilder("a.GoodsID in(");
     
        string[] keys = HttpUtility.UrlDecode(cookie.Value).Trim().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
        List<string> List = new List<string>();
        foreach (string item in keys)
        {
           
                int GiftID = Convert.ToInt32(item.Split(new char[] { ',' })[0]);
                List.Add(item);
                sbWhere.AppendFormat("{0},", GiftID);
           

        }
        
        sbWhere.Append("0)");
        DataTable dt = MicroWebsiteGoodsBll.GetOKGoods(sbWhere.ToString()).Tables[0];
        dt = this.UpDateTable(dt, List);
        this.rptGoodsCard.DataSource = dt;
        this.rptGoodsCard.DataBind();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie cookie = base.Request.Cookies["goodlist"];
        if ((cookie != null) && !string.IsNullOrEmpty(cookie.Value))
        {
            this.DataBindGoodCard(cookie);
            this.zhifu_price.InnerText = this.TotalSubtotal.ToString("0.00");
            this.foot.Style.Add("display", "");
        }
        else
        {
        this.msg.Style.Add("display", "");
        }
    }

    private DataTable UpDateTable(DataTable dt, string[] keys)
    {
        dt.Columns.Add("ConvertNumber");
        dt.Columns.Add("Subtotal");
        foreach (string item in keys)
        {
            int MicroGoodsID = Convert.ToInt32(item.Split(new char[] { ',' })[0]);
            int ConvertNumber = Convert.ToInt32(item.Split(new char[] { ',' })[2]);
            DataRow row = dt.Select("GoodsID=" + MicroGoodsID)[0];
            row["ConvertNumber"] = ConvertNumber;
            row["Subtotal"] = ConvertNumber * Convert.ToDecimal(row["Price"]);
            this.TotalSubtotal += Convert.ToDecimal(row["Subtotal"]);
        }
        return dt;
    }
    private DataTable UpDateTable(DataTable dt, List<string> keys)
    {
        dt.Columns.Add("ConvertNumber");
        dt.Columns.Add("Subtotal");
        foreach (string item in keys)
        {
            int MicroGoodsID = Convert.ToInt32(item.Split(new char[] { ',' })[0]);
            int ConvertNumber = Convert.ToInt32(item.Split(new char[] { ',' })[2]);
            DataRow row = dt.Select("GoodsID=" + MicroGoodsID)[0];
            row["ConvertNumber"] = ConvertNumber;
            row["Subtotal"] = ConvertNumber * Convert.ToDecimal(row["Price"]);
            this.TotalSubtotal += Convert.ToDecimal(row["Subtotal"]);
        }
        return dt;
    }
}